//
//  OrderDetailView.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/18.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#define NavigationHeightFix 64

#import "OrderDetailView.h"
#import "OrderDetailViewHelper.h"
@interface OrderDetailView(){
    JFBOrderDS *_order;
    OrderDetailViewHelper *_headerView;
}
@end

@implementation OrderDetailView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = frame;
        [self initSubView];
        
    }
    return self;
}


- (void)initSubView{
    [self setBackgroundColor:PanelBgColorDefault];
    _headerView = [[OrderDetailViewHelper alloc] init];
    [_headerView setBackgroundColor:[UIColor redColor]];
    [self addSubview:_headerView];
}

-(void)setOrder:(JFBOrderDS *)order{
    _order = order;
    UIView *headerView = [self undealerDetailView];
//    CGRect rect = CGRectMake(0, kOrderCellMargin + NavigationHeightFix, headerView.bounds.size.width, headerView.bounds.size.height);
    headerView.frame = CGRectMake(0, kOrderCellMargin + NavigationHeightFix, headerView.bounds.size.width, 100);
    [headerView setBackgroundColor:[UIColor redColor]];
//    [headerView setBackgroundColor:PanelBgColorDefault];
//    [self addSubview:headerView];
}

- (UIView*)undealerDetailView {
    OrderDetailViewHelper *hview = _headerView;
//    OrderDetailViewHelper *hview = [[OrderDetailViewHelper alloc] init];
    
    [hview setBackgroundColor:[UIColor redColor]];
    
    UILabel * _requireTimeLabel = [[UILabel alloc] init];
    _requireTimeLabel.font = [UIFont systemFontOfSize:TextFontSizeH3];
    _requireTimeLabel.textColor = TextColorImportant;
    [hview addSubview:_requireTimeLabel];
    
    CGSize requireTimeSize = [_order.requireTime sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH2]}];
    CGFloat requireTimeX = kOrderCellMargin, requireTimeY = (kOrderCellHeaderHeight - requireTimeSize.height) / 2;
    CGRect requireTimeRect = CGRectMake(requireTimeX, requireTimeY, requireTimeSize.width, requireTimeSize.height);
    _requireTimeLabel.text = _order.requireTime;
    _requireTimeLabel.frame = requireTimeRect;
    
    [hview addHorizontalLine:kOrderCellHeaderHeight color:LineColorImportant isFull:true];

    UILabel *_userNameLabel = [[UILabel alloc] init];
    _userNameLabel.font = [UIFont systemFontOfSize:TextFontSizeH3];
    _userNameLabel.textColor = TextColorDefault;
    [hview addSubview:_userNameLabel];
    
    CGSize userNameSize = [_order.userName sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH2]}];
    CGFloat userNameY = kOrderCellHeaderHeight + kOrderCellSpacing;
    CGFloat userNameX = kOrderCellMargin;
    CGRect userNameRect = CGRectMake(userNameX, userNameY, userNameSize.width, userNameSize.height);
    _userNameLabel.text = _order.userName;
    _userNameLabel.frame = userNameRect;
    
    UILabel *_addressLabel = [[UILabel alloc] init];
    _addressLabel.font = [UIFont systemFontOfSize:TextFontSizeH3];
    _addressLabel.textColor = TextColorDefault;
    [hview addSubview:_addressLabel];
    
    CGSize addressSize = [_order.address sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH2]}];
    CGFloat addressY = userNameY + userNameSize.height + kOrderCellSpacing;
    CGFloat addressX = kOrderCellMargin;
    CGRect addressRect = CGRectMake(addressX, addressY, addressSize.width, addressSize.height);
    _addressLabel.text = _order.address;
    _addressLabel.frame = addressRect;
    
    
    return hview;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
